//
//  MYNewsShopDetailsCommentVC.m
//  MuYing
//
//  Created by tbb on 2020/3/7.
//  Copyright © 2020 TBB. All rights reserved.
//

#import "MYNewsShopDetailsCommentVC.h"
#import "MYNewsShopDetailsModel.h"
@interface MYNewsShopDetailsCommentVC ()

@end

@implementation MYNewsShopDetailsCommentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = kYQLS(@"评论列表");
}

- (void)setupView {
    [super setupView];
    kYQREGISTERTABLEVIEWNIBCELL(@"MYShopDetailsCommentCell")
    [self setupRefresh:self.listTableView];
    [self onStartRefresh];
    YQSHOWLOADINGINVIEW;
}

- (void)onStartRefresh {
    self.page = 1;
    [self getCommetnList];
}

- (void)onStartLoadMore {
    self.page ++ ;
    [self getCommetnList];
}

-(void)getCommetnList {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"id"] = self.informationId;
    parameters[@"limit"] = @"10";
    parameters[@"page"] = @(self.page);
    
    NSString *url = @"";
    if (self.type == 0) {
        url = kPOST_HOTEL_HOTEL_COMMETN_LIST_URL;
    }else if (self.type == 1) {
        url = kPOST_SCENERY_SCENERY_COMMETN_LIST_URL;
    }else{
        url = kPOST_COURSE_COURES_COMMETN_LIST_URL;
    }
    
    [YQPNetWorkingManager sendPostRequest:url parameters:parameters success:^(YQPNetWorkingBaseModel * _Nonnull responseObject) {
        [self stopRefresh];
        YQHIDELOADINGTIPS
        if (responseObject.code == 0) {
            if (self.page == 1) {
                [self.dataArr removeAllObjects];
            }
            NSArray *arr = [NSArray modelArrayWithClass:[MYNewsShopDetailsCommentModel class] json:responseObject.data[@"list"]];
            [self.dataArr addObjectsFromArray:arr];
            [self.listTableView reloadData];
            if (arr.count < 10) {
                [self.listTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }else{
            YQUITIPSERROR(responseObject.msg)
        }
    } failure:^(NSUInteger statusCode, NSString * _Nonnull error) {
        YQUITIPSERROR(error)
        [self stopRefresh];
        YQHIDELOADINGTIPS
    }];
    
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    MYShopDetailsCommentCell *commentCell = [tableView dequeueReusableCellWithIdentifier:@"MYShopDetailsCommentCell"];
    
    MYNewsShopDetailsCommentModel *commentModel = nil;
    if (indexPath.row < self.dataArr.count) {
        commentModel = self.dataArr[indexPath.row];
    }
    commentCell.commentModel = commentModel;
    
    return commentCell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    MYNewsShopDetailsCommentModel *commentModel = nil;
    if (indexPath.row < self.dataArr.count) {
        commentModel = self.dataArr[indexPath.row];
    }
    return [tableView fd_heightForCellWithIdentifier:@"MYShopDetailsCommentCell" configuration:^(MYShopDetailsCommentCell *cell) {
        cell.commentModel = commentModel;
    }];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.001;
}
#pragma mark - UITableViewDelegate, UITableViewDataSource end

@end
